Don't deadlock when a dep has no libs
authorAlex Crichton <alex@alexcrichton.com>
Sun, 7 Sep 2014 18:48:35 +0000 (11:48 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 7 Sep 2014 18:48:35 +0000 (11:48 -0700)
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_compile.rs

index f9cb09631554ef291ec30159b0c17bc0ade51877..1ff4190a302a8c032d559139fe5191c80c058c4f 100644 (file)
@@ -81,6 +81,10 @@ pub fn compile_targets<'a>(env: &str, targets: &[&'a Target], pkg: &'a Package,
             cx.is_relevant_target(*target)
         }).collect::<Vec<&Target>>();
 
+        if targets.len() == 0 {
+            return Err(human(format!("Package `{}` has no library targets", dep)))
+        }
+
         try!(compile(targets.as_slice(), dep, &mut cx, &mut queue));
     }
 
index 9c754cc347e9365f0fd4bc50a0640f33b06aa68b..efaa330c8db55bd6e96959ff2351b65a959a5688 100644 (file)
@@ -1641,3 +1641,28 @@ test!(rebuild_preserves_out_dir {
 {compiling} foo v0.0.0 ({url})
 ", compiling = COMPILING, url = foo.url())));
 })
+
+test!(dep_no_libs {
+    let foo = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.0"
+            authors = []
+
+            [dependencies.bar]
+            path = "bar"
+        "#)
+        .file("src/lib.rs", "pub fn bar() -> int { 1 }")
+        .file("bar/Cargo.toml", r#"
+            [package]
+            name = "bar"
+            version = "0.0.0"
+            authors = []
+        "#)
+        .file("bar/src/main.rs", "");
+    assert_that(foo.cargo_process("build"),
+                execs().with_status(101)
+                       .with_stderr("\
+Package `bar v0.0.0 ([..])` has no library targets"));
+})